#pragma once
#include <iostream>
using namespace std;

namespace ts
{
	template<class T>
	struct ListNode
	{
		ListNode<T>* _prev;
		ListNode<T>* _next;
		T _data;

		ListNode(const T& data = T())
			:_prev(nullptr)
			,_next(nullptr)
			,_data(data)
		{}
	};

	template<class T>
	struct __list_iterator
	{
		typedef ListNode<T> Node;
		//typedef __list_iterator 
		Node* _node;

		__list_iterator(Node* x)
			:_node(x)
		{}

		T& operator*()
		{
			return _node->_data;
		}

		//++it
		__list_iterator<T>& operator++()
		{
			_node = _node->_next;
			return *this;
		}

		//it++
		__list_iterator<T>& operator++(int)
		{
			__list_iterator<T> tmp(*this);
			_node = _node->_next;
			return tmp;
		}
	};

	template<class T>
	class list
	{
		typedef ListNode<T> Node;

	public:
		list()
		{
			_head = new Node;
			_head->_next = _head;
			_head->_prev = _head;
		}

		void push_back(const T& x)
		{
			Node* newNode = new Node(x);
			Node* tail = _head->_prev;
			tail->_next = newNode;
			newNode->_prev = tail;
			newNode->_next = _head;
			_head->_prev = newNode;
		}

	private:
		Node* _head;	
	};

	void test_list1()
	{
		list<int> l1;
		l1.push_back(1);
		l1.push_back(2);
		l1.push_back(3);
		l1.push_back(4);
	}

}